package com.quotes.simulation;

import java.text.*;
import com.quotes.datamodell.TimeSeries;

public class SimulationResult 
{
	private double initialCash = 0;
	private int buyCount = 0;
	private int sellCount = 0;
	private int lowOnCashCount = 0;
	private double wins = 0;
	private double losses = 0;
	private double fees;
	private TimeSeries valueDevelopment = null;

	public SimulationResult(double initialCash, int buyCount, int sellCount, int lowOnCashCount, double wins, double losses, double fees, TimeSeries valueDevelopment) {
		this.setInitialCash(initialCash);
		this.buyCount = buyCount;
		this.sellCount = sellCount;
		this.setLowOnCashCount(lowOnCashCount);
		this.wins = wins;
		this.losses = losses;
		this.fees = fees;
		this.valueDevelopment = valueDevelopment;
	}
	
	public double getInitialCash() {
		return initialCash;
	}

	public void setInitialCash(double initialCash) {
		this.initialCash = initialCash;
	}
	
	public int getBuyCount() {
		return buyCount;
	}
	
	public void setBuyCount(int buyCount) {
		this.buyCount = buyCount;
	}
	
	public int getSellCount() {
		return sellCount;
	}
	
	public void setSellCount(int sellCount) {
		this.sellCount = sellCount;
	}

	public double getWins() {
		return wins;
	}

	public void setWins(double wins) {
		this.wins = wins;
	}

	public double getLosses() {
		return losses;
	}

	public void setLosses(double losses) {
		this.losses = losses;
	}

	public TimeSeries getValueDevelopment() {
		return valueDevelopment;
	}

	public void setValueDevelopment(TimeSeries valueDevelopment) {
		this.valueDevelopment = valueDevelopment;
	}

	public double getFees() {
		return fees;
	}

	public int getLowOnCashCount() {
		return lowOnCashCount;
	}

	public void setLowOnCashCount(int lowOnCashCount) {
		this.lowOnCashCount = lowOnCashCount;
	}

	public void setFees(double fees) {
		this.fees = fees;
	}
	
	public double getEndValue() {
		return valueDevelopment.getEndValue();
	}
	
	public boolean wasGoodResult() {
		return getEndValue() >= getInitialCash();
	}
	
	public double getResult() {
		return getEndValue() - getInitialCash();
	}
	
	public int getDaysAboveInitialCash() {
		return valueDevelopment.substract(getInitialCash()).filterPositiveValues().filterZeros().size();
	}
	
	public int getDaysBelowInitialCash() {
		return valueDevelopment.substract(getInitialCash()).filterNegativeValues().filterZeros().size();
	}
	
	@Override
	public String toString() {
		DecimalFormat numberFormat = new DecimalFormat("#0.00");
		String message = "";
		
		if (wasGoodResult())
			message += "WON: " + numberFormat.format(getResult());
		else 
			message += "LOST: " + numberFormat.format(getResult());
		
		message += ". DaysAbove: " + getDaysAboveInitialCash() + 
				". DaysBelow: " + getDaysBelowInitialCash() +
				". BuyCount: " + buyCount + 
				". SellCount: " + sellCount + 
				". LowOnCashCount: " + getLowOnCashCount() +
				". Wins: " + numberFormat.format(wins) +
				". Losses: " + numberFormat.format(losses) +
				". Fees: " + numberFormat.format(fees) + 
				". AverageWin: " + numberFormat.format(wins / buyCount) +
				". AverageLoss: " + numberFormat.format(losses / sellCount);
		
		return message;
	}
}
